echo off
rem Android NDK 交叉编译脚本,创建Makefile
rem author guyadong

rem 检测是否安装NDK,没有安装NDK则报错退出
if not DEFINED ANDROID_NDK (
	echo "ERROR:environment variable ANDROID_NDK not define" && exit /B -1
	)
where cmake
if errorlevel 1 (
	echo cmake NOT FOUND.
	exit /B -1
)

set sh_folder=%~dp0
rem 定义编译的版本类型(DEBUG|RELEASE)
set build_type=RELEASE
rem OpenCV源码路径
set opencv_source="E:\caffe-static\source\opencv-2.4.13.2"
if "%1" == "DEBUG" set build_type=%1
echo build_type=%build_type%

pushd %sh_folder%..
if exist opencv.ndk.prj rmdir  opencv.ndk.prj /s/q
mkdir opencv.ndk.prj

pushd opencv.ndk.prj
cmake %opencv_source% -G "Eclipse CDT4 - MinGW Makefiles" -DCMAKE_BUILD_TYPE:STRING=release ^
	-DBUILD_DOCS=off ^
	-DBUILD_SHARED_LIBS=off ^
	-DBUILD_PACKAGE=on ^
	-DBUILD_PERF_TESTS=off ^
	-DBUILD_FAT_JAVA_LIB=off ^
	-DBUILD_TESTS=off ^
	-DBUILD_TIFF=on ^
	-DBUILD_JASPER=on ^
	-DBUILD_JPEG=on ^
	-DBUILD_OPENEXR=on ^
	-DBUILD_PNG=on ^
	-DBUILD_ZLIB=on ^
	-DBUILD_opencv_apps=off ^
	-DBUILD_opencv_calib3d=off ^
	-DBUILD_opencv_contrib=off ^
	-DBUILD_opencv_features2d=off ^
	-DBUILD_opencv_flann=off ^
	-DBUILD_opencv_gpu=off ^
	-DBUILD_opencv_java=off ^
	-DBUILD_opencv_legacy=off ^
	-DBUILD_opencv_ml=off ^
	-DBUILD_opencv_nonfree=off ^
	-DBUILD_opencv_objdetect=off ^
	-DBUILD_opencv_ocl=off ^
	-DBUILD_opencv_photo=off ^
	-DBUILD_opencv_python=off ^
	-DBUILD_opencv_stitching=off ^
	-DBUILD_opencv_superres=off ^
	-DBUILD_opencv_ts=off ^
	-DBUILD_opencv_video=off ^
	-DBUILD_opencv_videostab=off ^
	-DBUILD_opencv_world=off ^
	-DBUILD_opencv_lengcy=off ^
	-DWITH_DSHOW=off ^
	-DWITH_JASPER=on ^
	-DWITH_JPEG=on ^
	-DWITH_1394=off ^
	-DWITH_OPENEXR=on ^
	-DWITH_PNG=on ^
	-DWITH_TIFF=on ^
	-DWITH_1394=off ^
	-DWITH_EIGEN=off ^
	-DWITH_FFMPEG=off ^
	-DWITH_GIGEAPI=off ^
	-DWITH_GSTREAMER_0_10=off ^
	-DWITH_PVAPI=off ^
	-DWITH_CUDA=off ^
	-DWITH_CUFFT=off ^
	-DWITH_OPENCL=off ^
	-DWITH_QT=off ^
	-DWITH_VFW=off ^
	-DWITH_VTK=off ^
	-DWITH_XIMEA=off ^
	-DWITH_WIN32UI=off ^
	-DCMAKE_SYSTEM_VERSION=17 ^
	-DCMAKE_INSTALL_PREFIX=%sh_folder%release\opencv_android_armeabi-v7a ^
	-DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK%\build\cmake\android.toolchain.cmake 

popd
popd
